<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="BCR编号" prop="memItemCode">
        <el-input
          v-model="queryParams.memItemCode"
          placeholder="请输入BCR编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width:160px;"
        />
      </el-form-item>
      <el-form-item label="状态" prop="dealFlag">
        <el-select v-model="queryParams.dealFlag" style="width:140px;" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in dealFlagOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:WcsMemPlc:add']"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:WcsMemPlc:edit']"
        >修改</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:WcsMemPlc:remove']"
        >删除</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:WcsMemPlc:export']"
        >导出</el-button>
      </el-col>

	    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

    </el-row>



    <el-table v-loading="loading" :data="WcsMemPlcList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column label="BCR名称" min-width="140" align="center" prop="memItemNo"  />
      <el-table-column label="BCR编号" align="center" prop="memItemCode"  />
      <el-table-column label="BCR说明" align="center" min-width="140" prop="memItemDesc" :show-overflow-tooltip="true" />
      <el-table-column label="读码失败地址" align="center" min-width="160" prop="errExceptionNo"  />
      <el-table-column label="无任务地址" align="center" min-width="160" prop="noExceptionNo"  />
      <el-table-column label="状态" align="center" prop="dealFlag" :formatter="dealFlagFormat" />
      <!-- <el-table-column label="操作" align="center" width="140" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:WcsMemPlc:edit']"
          >修改</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:WcsMemPlc:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改BCR参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="BCR名称" prop="memItemNo">
          <el-input v-model="form.memItemNo" placeholder="请输入BCR名称" />
        </el-form-item>
        <el-form-item label="BCR编号" prop="memItemCode">
          <el-input v-model="form.memItemCode" placeholder="请输入BCR编号" />
        </el-form-item>
        <el-form-item label="BCR说明" prop="memItemDesc">
          <el-input v-model="form.memItemDesc" placeholder="请输入BCR说明" />
        </el-form-item>
        <el-form-item label="读码失败地址" prop="errExceptionNo">
          <el-input v-model="form.errExceptionNo" placeholder="请输入读码失败地址" />
        </el-form-item>
        <el-form-item label="无任务地址" prop="noExceptionNo">
          <el-input v-model="form.noExceptionNo" placeholder="请输入无任务地址" />
        </el-form-item>
        <el-form-item label="状态" prop="dealFlag">
          <el-select v-model="form.dealFlag" placeholder="请选择状态">
            <el-option
              v-for="dict in dealFlagOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWcsMemPlc, getWcsMemPlc, delWcsMemPlc, addWcsMemPlc, updateWcsMemPlc, exportWcsMemPlc } from "@/api/system/WcsMemPlc";

export default {
  name: "WcsMemPlc",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // BCR参数配置表格数据
      WcsMemPlcList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // ID字典
      idOptions: [],
      // ASN单号字典
      dvcNoOptions: [],
      // BCR名称字典
      memItemNoOptions: [],
      // BCR类型字典
      memItemTypeOptions: [],
      // BCR编号字典
      memItemCodeOptions: [],
      // BCR说明字典
      memItemDescOptions: [],
      // ASN单号字典
      memItemValueOptions: [],
      // ASN单号字典
      memItemOldvalueOptions: [],
      // ASN单号字典
      stnNoOptions: [],
      // ASN单号字典
      memParaTypeOptions: [],
      // ASN单号字典
      updateTimeOptions: [],
      // 备注字典
      commentsOptions: [],
      // 读码失败地址字典
      errExceptionNoOptions: [],
      // 无任务地址字典
      noExceptionNoOptions: [],
      // ASN单号字典
      noValueOptions: [],
      // ASN单号字典
      errValueOptions: [],
      // ASN单号字典
      noCurrCountOptions: [],
      // ASN单号字典
      errCurrCountOptions: [],
      // 状态字典
      dealFlagOptions: [],
      // ASN单号字典
      asnnumberOptions: [],
      // ASN单号号字典
      labernumOptions: [],
      // ASN单号字典
      djlxOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dvcNo: null,
        memItemNo: null,
        memItemType: null,
        memItemCode: null,
        memItemDesc: null,
        memItemValue: null,
        memItemOldvalue: null,
        stnNo: null,
        memParaType: null,
        updateTime: null,
        comments: null,
        errExceptionNo: null,
        noExceptionNo: null,
        noValue: null,
        errValue: null,
        noCurrCount: null,
        errCurrCount: null,
        dealFlag: null,
        asnnumber: null,
        labernum: null,
        djlx: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        memItemNo: [
          { required: true, message: "BCR名称不能为空", trigger: "blur" },
        ],
        memItemCode: [
          { required: true, message: "BCR编号不能为空", trigger: "blur" },
        ],
        errExceptionNo: [
          { required: true, message: "读码失败地址不能为空", trigger: "blur" },
        ],
        noExceptionNo: [
          { required: true, message: "无任务地址不能为空", trigger: "blur" },
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("${column.dictType}").then(response => {
      this.idOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.dvcNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.memItemNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.memItemTypeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.memItemCodeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.memItemDescOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.memItemValueOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.memItemOldvalueOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.stnNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.memParaTypeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.updateTimeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.commentsOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.errExceptionNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.noExceptionNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.noValueOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.errValueOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.noCurrCountOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.errCurrCountOptions = response.data;
    });
    this.getDicts("sys_job_status").then(response => {
      this.dealFlagOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.asnnumberOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.labernumOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.djlxOptions = response.data;
    });
  },
  methods: {
    /** 查询BCR参数配置列表 */
    getList() {
      this.loading = true;
      listWcsMemPlc(this.queryParams).then(response => {
        this.WcsMemPlcList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // ID字典翻译
    idFormat(row, column) {
      return this.selectDictLabel(this.idOptions, row.id);
    },
    // ASN单号字典翻译
    dvcNoFormat(row, column) {
      return this.selectDictLabel(this.dvcNoOptions, row.dvcNo);
    },
    // BCR名称字典翻译
    memItemNoFormat(row, column) {
      return this.selectDictLabel(this.memItemNoOptions, row.memItemNo);
    },
    // BCR类型字典翻译
    memItemTypeFormat(row, column) {
      return this.selectDictLabel(this.memItemTypeOptions, row.memItemType);
    },
    // BCR编号字典翻译
    memItemCodeFormat(row, column) {
      return this.selectDictLabel(this.memItemCodeOptions, row.memItemCode);
    },
    // BCR说明字典翻译
    memItemDescFormat(row, column) {
      return this.selectDictLabel(this.memItemDescOptions, row.memItemDesc);
    },
    // ASN单号字典翻译
    memItemValueFormat(row, column) {
      return this.selectDictLabel(this.memItemValueOptions, row.memItemValue);
    },
    // ASN单号字典翻译
    memItemOldvalueFormat(row, column) {
      return this.selectDictLabel(this.memItemOldvalueOptions, row.memItemOldvalue);
    },
    // ASN单号字典翻译
    stnNoFormat(row, column) {
      return this.selectDictLabel(this.stnNoOptions, row.stnNo);
    },
    // ASN单号字典翻译
    memParaTypeFormat(row, column) {
      return this.selectDictLabel(this.memParaTypeOptions, row.memParaType);
    },
    // ASN单号字典翻译
    updateTimeFormat(row, column) {
      return this.selectDictLabel(this.updateTimeOptions, row.updateTime);
    },
    // 备注字典翻译
    commentsFormat(row, column) {
      return this.selectDictLabel(this.commentsOptions, row.comments);
    },
    // 读码失败地址字典翻译
    errExceptionNoFormat(row, column) {
      return this.selectDictLabel(this.errExceptionNoOptions, row.errExceptionNo);
    },
    // 无任务地址字典翻译
    noExceptionNoFormat(row, column) {
      return this.selectDictLabel(this.noExceptionNoOptions, row.noExceptionNo);
    },
    // ASN单号字典翻译
    noValueFormat(row, column) {
      return this.selectDictLabel(this.noValueOptions, row.noValue);
    },
    // ASN单号字典翻译
    errValueFormat(row, column) {
      return this.selectDictLabel(this.errValueOptions, row.errValue);
    },
    // ASN单号字典翻译
    noCurrCountFormat(row, column) {
      return this.selectDictLabel(this.noCurrCountOptions, row.noCurrCount);
    },
    // ASN单号字典翻译
    errCurrCountFormat(row, column) {
      return this.selectDictLabel(this.errCurrCountOptions, row.errCurrCount);
    },
    // 状态字典翻译
    dealFlagFormat(row, column) {
      return this.selectDictLabel(this.dealFlagOptions, row.dealFlag);
    },
    // ASN单号字典翻译
    asnnumberFormat(row, column) {
      return this.selectDictLabel(this.asnnumberOptions, row.asnnumber);
    },
    // ASN单号号字典翻译
    labernumFormat(row, column) {
      return this.selectDictLabel(this.labernumOptions, row.labernum);
    },
    // ASN单号字典翻译
    djlxFormat(row, column) {
      return this.selectDictLabel(this.djlxOptions, row.djlx);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dvcNo: null,
        memItemNo: null,
        memItemType: null,
        memItemCode: null,
        memItemDesc: null,
        memItemValue: null,
        memItemOldvalue: null,
        stnNo: null,
        memParaType: null,
        updateTime: null,
        comments: null,
        errExceptionNo: null,
        noExceptionNo: null,
        noValue: null,
        errValue: null,
        noCurrCount: null,
        errCurrCount: null,
        dealFlag: null,
        asnnumber: null,
        labernum: null,
        djlx: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加BCR参数配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWcsMemPlc(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改BCR参数配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWcsMemPlc(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addWcsMemPlc(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除BCR参数配置编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWcsMemPlc(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有BCR参数配置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportWcsMemPlc(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
